import modelExtend from '../../../utils/modelExtend';
import HttpModel from '../../../models/http';
import { doGet } from '@/services/http';
let functionConfig = {
    namespace: 'functionConfig',
    state: {
        pageList: {
            list: [],
            pagination: {},
        },
        data: {},
    },
    effects: {
        *fetchPageData({ payload, callback }, { call, put }) {
            const response = yield call(doGet, payload);
            if (response.statusCode === '0') {
                yield put({ type: 'req', payload: { pageList: response.data } });
                if (callback) callback(response);
                return response;
            }
        },
        *initData({ payload, callback }, { call, put }) {
            yield put({
                type: 'req',
                payload: {
                    pageList: {
                        list: [],
                        pagination: {},
                    },
                    data: {},
                },
            });
        },
    },
    reducers: {
        req(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
    },
};
functionConfig = modelExtend(HttpModel, functionConfig);
export default functionConfig;